package com.hengpeng.itfinoss.controller.vo;

import java.util.ArrayList;
import java.util.List;

import com.hengpeng.common.acl.vo.ActionObject;
import com.hengpeng.common.acl.vo.NodeObject;
import com.hengpeng.common.acl.vo.Permission;

/**
 * <pre>
 * 权限对象，前台使用
 * </pre>
 * @author chenjian
 * @version 1.0, 2010-9-1
 */
public class PermissionVo
{
	private String id;

	private String description;

	private String parentId;

	private List<PermissionVo> child = new ArrayList<PermissionVo>();

	public String getId()
	{
		return id;
	}

	public void setId(String id)
	{
		this.id = id;
	}

	public String getDescription()
	{
		return description;
	}

	public void setDescription(String description)
	{
		this.description = description;
	}

	public String getParentId()
	{
		return parentId;
	}

	public void setParentId(String parentId)
	{
		this.parentId = parentId;
	}

	public List<PermissionVo> getChild()
	{
		return child;
	}

	public void setChild(List<PermissionVo> child)
	{
		this.child = child;
	}

	public static List<PermissionVo> clone(List<Permission> permissionList)
	{
		List<PermissionVo> voList = new ArrayList<PermissionVo>();
		if (permissionList != null)
		{
			for (Permission permission : permissionList)
			{
				voList.add(clone(permission));
			}
		}
		return voList;
	}

	public static PermissionVo clone(Permission permission)
	{
		if (permission != null)
		{
			PermissionVo vo = new PermissionVo();
			vo.setId(permission.getId());
			vo.setDescription(permission.getDescription());
			if (permission.getParent() != null)
			{
				vo.setParentId(permission.getParent().getId());
			}
			List<PermissionVo> voList = new ArrayList<PermissionVo>();
			ActionObject[] childActions = permission.getChildActions();
			NodeObject[] childNodes = permission.getChildNodes();
			for (ActionObject action : childActions)
			{
				PermissionVo __vo = clone(action);
				voList.add(__vo);
			}
			for (NodeObject action : childNodes)
			{
				PermissionVo __vo = clone(action);
				voList.add(__vo);
			}
			vo.setChild(voList);
			return vo;
		}
		return null;
	}
}
